package com.ktwlsoft.archivemanage.domain.business.repositoryService;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.base.CaseFormat;
import com.ktwlsoft.archivemanage.domain.dao.entity.UnitArchiveManage;
import com.ktwlsoft.archivemanage.domain.dao.entity.UnitArchives;
import com.ktwlsoft.archivemanage.domain.dao.repository.IUnitArchiveManageMapper;
import com.ktwlsoft.archivemanage.payload.Result;
import com.ktwlsoft.archivemanage.payload.ResultType;
import com.ktwlsoft.archivemanage.payload.archiveUnit.UnitArchivesOfYears;
import com.ktwlsoft.archivemanage.payload.transfer.*;
import com.ktwlsoft.archivemanage.payload.unitArchiveManage.Archive;
import com.ktwlsoft.archivemanage.payload.unitArchiveManage.ArchiveUnitStatics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.Size;
import java.time.Year;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author chenkun
 * @version 1.0
 * @description 室藏档案管理数据层服务类
 * @date 2019-10-28
 */
@Service
public class UnitArchiveManageRepositoryService {
    @Autowired
    private IUnitArchiveManageMapper iUnitArchiveManageMapper;

    /**
     * @param data
     * @return List<Map < String, Object>>
     * @description 查询室藏档案管理列表
     */
    public List<Map<String, Object>> findUnitArchiveManageList(Map<String, Object> data) {
        List<Map<String, Object>> list = iUnitArchiveManageMapper.findUnitArchiveManageList(data);
        return list;
    }

    /**
     * @param data
     * @return Map<String, Object>
     * @description 查询室藏档案管理信息
     */
    public Map<String, Object> findUnitArchiveManageInfo(Map<String, Object> data) {
        Map<String, Object> result = iUnitArchiveManageMapper.findUnitArchiveManageInfo(data);
        return result;
    }

    /**
     * @param unitArchiveManage
     * @return Result
     * @description 新增室藏档案管理信息
     */
    public int addUnitArchiveManage(UnitArchiveManage unitArchiveManage) {
        return iUnitArchiveManageMapper.addUnitArchiveManage(unitArchiveManage);
    }

    /**
     * description 删除室藏档案信息
     *
     * @param id
     * @return Result
     */
    public int deleteUnitArchiveManage(Long id) {
        return iUnitArchiveManageMapper.deleteUnitArchiveManage(id);
    }

    /**
     * description 编辑室藏档案信息
     *
     * @param unitArchiveManage
     * @return int
     */
    public int updateUnitArchiveManage(UnitArchiveManage unitArchiveManage) {
        return iUnitArchiveManageMapper.updateUnitArchiveManage(unitArchiveManage);
    }

    /**
     * @param unitArchiveManage
     * @return int
     * @description 更新对比确认状态
     */
    public int updateCompareConfirm(UnitArchiveManage unitArchiveManage) {
        return iUnitArchiveManageMapper.updateCompareConfirm(unitArchiveManage);
    }

    public List<TransferListResponse> findTransferListByPage(String keywords, Boolean transfered) {
        return iUnitArchiveManageMapper.findTransferListByPage(keywords, transfered);
    }

    public TransferDetail findTransferDetailById(Long id) {
        return iUnitArchiveManageMapper.findTransferDetailById(id);
    }

    public List<TransferDetailList> findTransferDetailList(Long unitId, String field, String order) {
        field = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field);
        return iUnitArchiveManageMapper.findTransferDetailListByUnitId(unitId, field, order);
    }

    public int setTransfered(Long businessId,
                             String realName,
                             Long userId,
                             String transferRemark,
                             Date date) {
        return iUnitArchiveManageMapper.setTransfered(businessId, realName, userId, transferRemark, date);
    }

    public int cancelTransfer(Long businessId,
                              String realName,
                              Long userId,
                              String transferRemark,
                              Date date) {
        return iUnitArchiveManageMapper.cancelTransfer(businessId, realName, userId, transferRemark, date);
    }

    public boolean existByUnitAndYear(Long unitId, Year writeDate) {
        return iUnitArchiveManageMapper.findByUnitAndYear(unitId, writeDate) != null;
    }

    public ArchiveUnitStatics findUnitStatics(Long unitId) {
        return iUnitArchiveManageMapper.findUnitStatics(unitId);
    }

    public List<Archive> findUnitArchiveTypesStatistic(Long unitId) {
        return iUnitArchiveManageMapper.findUnitArchiveTypesStatistic(unitId);
    }
}
